<template>
  <el-container>
    <el-header height="70px">
      <div class="log0"></div>
      <!-- 用户显示信息 -->
      <div class="user">
        <img src="../../assets/pic.jpg" alt="图片未加载" class="pic" />
        <span class="username">西门吹雪</span>
      </div>
      <div class="btn">
        <el-button @click="upExam">退出</el-button>
      </div>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <!-- @open="handleOpen"
          @close="handleClose" -->
        <el-menu default-active="/detail/single/1"
          class="el-menu-vertical-demo"
          active-text-color="#409EFF"
          unique-opened
          router
        >
          <!--
                将:index=“item.path”
                改为:index="item.path + ’ ’ "
                完美解决
                    原因：elementUI的index是字符串格式，加一个‘ ’，将后台数据转换为字符串
             -->

          <el-submenu :index="item.id + ''" v-for="item in exam" :key="item.id">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{ item.name }}（每题5分）</span>
            </template>
            <el-menu-item
              :index="`/detail/${topic[item.name]}/${topicItem.id}`"
              v-for="topicItem in item.topic"
              :key="item.id + '-' + topicItem.id"
              >题目{{ topicItem.id }}
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { mapState } from 'vuex'
export default {
  data () {
    return {
      topic: { 单选题: 'single', 多选题: 'multiple', 判断题: 'judge' }
    }
  },
  mounted () {
    this.getData()
  },
  computed: {
    // ...mapState(['Allexam'])
    ...mapState({
      exam: (state) => state.exam.Allexam
    })
  },
  methods: {
    async getData () {
      const result = await this.$api.exam.selectOneExam(this.$route.query.examId)
      console.log(result)
    },
    // 退出按钮
    upExam () {
      this.$confirm(
        '你是否要退出?',
        '退出',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      )
        .then(() => {
          this.$message({
            type: 'success',
            message: '退出成功!'
          })
          // 交卷请求
          this.$router.push({ path: '/teach/exam' })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    }
  }
}
</script>

<style scoped>
* {
  padding: 0;
  margin: 0;
}
.el-header {
  background-color: #b3c0d1;
  color: #fff;
  background: black;
  line-height: 70px;
}

.el-aside {
  background-color: #fff;
  color: #333;
  line-height: 200px;
  height: 93vh;
}

.el-main {
  background-color: #eee;
  color: #333;
  padding: 20px 10px 50px 25px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
/* 显示用户信息 */
.pic {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  vertical-align: center;
}
.user {
  float: right;
  width: 200px;
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.username {
  font-size: 16px;
  color: white;
  margin: 5px;
}
/* 按钮 */
.btn {
  float: right;
  margin-left: 40px;
}
.el-button {
  padding: 0 16px;
  height: 30px;
  background: black;
  color: rgba(255, 0, 0, 0.6);
  border-color: rgba(255, 0, 0, 0.6);
}
.el-button:hover {
  color: rgba(255, 0, 0, 1);
  border-color: rgba(255, 0, 0, 1);
}
/* 时间 */
.time {
  font-size: 18px;
  float: right;
}
</style>
